package ru.paswd.compare.rest;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

public class MatrixTest {

    @Test
    public void testMultiplication1() {
        Matrix matrix1 = new Matrix(Arrays.asList(
                Arrays.asList(4., 2.),
                Arrays.asList(9., 0.)
        ));

        Matrix matrix2 = new Matrix(Arrays.asList(
                Arrays.asList(3., 1.),
                Arrays.asList(-3., 4.)
        ));

        Matrix expected = new Matrix(Arrays.asList(
                Arrays.asList(6., 12.),
                Arrays.asList(27., 9.)
        ));

        equalsMatrix(expected, Matrix.multiply(matrix1, matrix2));
    }
    @Test
    public void testMultiplication2() {
        Matrix matrix1 = new Matrix(Arrays.asList(
                Arrays.asList(2., 1.),
                Arrays.asList(-3., 0.),
                Arrays.asList(4., -1.)
        ));

        Matrix matrix2 = new Matrix(Arrays.asList(
                Arrays.asList(5., -1., 6.),
                Arrays.asList(-3., 0., 7.)
        ));

        Matrix expected = new Matrix(Arrays.asList(
                Arrays.asList(7., -2., 19.),
                Arrays.asList(-15., 3., -18.),
                Arrays.asList(23., -4., 17.)
        ));

        equalsMatrix(expected, Matrix.multiply(matrix1, matrix2));
    }

    void equalsMatrix(Matrix expected, Matrix actual) {
        Assertions.assertEquals(
                "Height:" + expected.getHeight(),
                "Height:" + actual.getHeight());
        Assertions.assertEquals(
                "Width:" + expected.getWidth(),
                "Width:" + actual.getWidth());

        for (int i = 0; i < expected.getHeight(); i++) {
            for (int j = 0; j < expected.getWidth(); j++) {
                Assertions.assertEquals(expected.get(i, j), actual.get(i, j));
            }
        }

    }
}
